package com.ljs.mywebsoket.controller;

import com.ljs.mywebsoket.util.JsonResult;
import com.ljs.mywebsoket.webserver.WebSocketServer;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

@Controller
public class DemoController {
    @RequestMapping("/index")
    @ResponseBody
    public ResponseEntity<String> index(){
        return ResponseEntity.ok("请求成功");

    }
    @RequestMapping("/towebsoket")
    public String towebsoket(){
        return "websoket";
    }
    @RequestMapping("/push/{userId}")
    @ResponseBody
    public JsonResult pushweb(@RequestParam("msg") String msg, @PathVariable("userId") String userId) throws IOException {
      JsonResult jsonResult=new JsonResult();

        WebSocketServer.sendInfo(msg,userId);
        jsonResult.setData(msg);
        jsonResult.setMsg("成功");
        return jsonResult;
    }
}
